//
// Created by wenyaxi on 24-10-28.
//
#include "ListNode.h"


ListNode *ListNode::of(const std::vector<int> &nums) {
    auto *dummy = new ListNode(0);
    ListNode *cur = dummy;
    for (auto num: nums) {
        cur->next = new ListNode(num);
        cur = cur->next;
    }
    return dummy->next;
}

std::ostream & operator<<(std::ostream &os, ListNode &node) {
    ListNode *p = &node;
    os << "{";
    while (p) {
        if (p->next) {
            os << p->val << ",";
        } else {
            os << p->val << "}";
        }
        p = p->next;
    }
    return os;
}
